/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.figures;

import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

import com.cea.papyrus.core.utils.Debug;
/*
 * to delete
 */
/**
 * 
 */
public class PackageAnchor extends ChopboxAnchor
{
	
	/**
	 * 
	 */
	private int channel=11;
	
	/**
	 * Constructs a new ChopboxAnchor.
	 */
	public boolean leftToRight = false;
	
	/**
	 * 
	 */
	public boolean topDown = false;
	
	/**
	 * 
	 */
	public int offsetH=50;
	
	/**
	 * 
	 */
	public int offsetV=50;
	
	
	/**
	 * 
	 */
	protected PackageAnchor() { 
	}

	/**
	 * Constructs a ChopboxAnchor with the given <i>owner</i> figure.
	 * 
	 * @param owner The owner figure
	 * 
	 * @since 2.0
	 */
	public PackageAnchor(PackageFigure owner) {
		super(owner);
	}

	/**
	 * Gets a Rectangle from {@link #getBox()} and returns the Point where a line from the
	 * center of the Rectangle to the Point <i>reference</i> intersects the Rectangle.
	 * 
	 * @param iReference 
	 * @param reference The reference point
	 * 
	 * @return The anchor location
	 */
	@Override
	public Point getLocation(Point iReference) {
		Debug.debug(this,"getLocation iReference: "+iReference, channel);
		
		Point p=super.getLocation(iReference); //p is the point of anchor with the rectangle
		Rectangle r = Rectangle.SINGLETON;
		r.setBounds(getBox());
		Point pp=new Point();
		if((p.y==r.y-1)   && (p.x>r.x +((PackageFigure)getOwner()).getHeaderWitdh())){
			pp.y=p.y+((PackageFigure)getOwner()).getHeaderHeight();}
		else {pp.y=p.y;}
		return new Point(p.x,pp.y);	
	}

	/**
	 * Returns the bounds of this ChopboxAnchor's owner.  Subclasses can override this method
	 * to adjust the box the anchor can be placed on.  For instance, the owner figure may have
	 * a drop shadow that should not be included in the box.
	 * 
	 * @return The bounds of this ChopboxAnchor's owner
	 * 
	 * @since 2.0
	 */
	@Override
	protected Rectangle getBox() {
		return getOwner().getBounds();
	}

	/**
	 * Returns the anchor's reference point. In the case of the ChopboxAnchor, this is the
	 * center of the anchor's owner.
	 * 
	 * @return The reference point
	 */
	@Override
	public Point getReferencePoint() {
		Point ref = getBox().getCenter();
		getOwner().translateToAbsolute(ref);
		return ref;
	}


	
	

}
